home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
utils
/
gdb36p4s.zoo
/
valprint.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-13
|
41KB
|
1,498 lines
/* Print values for GNU debugger gdb.
Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc.
This file is part of GDB.
GDB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
GDB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GDB; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include "defs.h"
#include "param.h"
#include "symtab.h"
#include "value.h"
/* GNU software is only expected to run on systems with 32-bit integers. */
#define UINT_MAX 0xffffffff
/* Maximum number of chars to print for a string pointer value
or vector contents, or UINT_MAX for no limit. */
static unsigned int print_max;
static void type_print_varspec_suffix ();
static void type_print_varspec_prefix ();
static void type_print_base ();
static void type_print_method_args ();
char **unsigned_type_table;
char **signed_type_table;
char **float_type_table;
/* Print repeat counts if there are more than this
many repetitions of an element in an array. */
#define REPEAT_COUNT_THRESHOLD 10
/* Print the character string STRING, printing at most LENGTH characters.
Printing stops early if the number hits print_max; repeat counts
are printed as appropriate. Print ellipses at the end if we
had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
void
print_string (stream, string, length, force_ellipses)
FILE *stream;
char *string;
unsigned int length;
int force_ellipses;
{
register unsigned int i;
unsigned int things_printed = 0;
int in_quotes = 0;
int need_comma = 0;
if (length == 0)
{
fputs_filtered ("\"\"", stdout);
return;
}
for (i = 0; i < length && things_printed < print_max; ++i)
{
/* Position of the character we are examining
to see whether it is repeated. */
unsigned int rep1;
/* Number of repititions we have detected so far. */
unsigned int reps;
QUIT;
if (need_comma)
{
fputs_filtered (", ", stream);
need_comma = 0;
}
rep1 = i + 1;
reps = 1;
while (rep1 < length && string[rep1] == string[i])
{
++rep1;
++reps;
}
if (reps > REPEAT_COUNT_THRESHOLD)
{
if (in_quotes)
{
fputs_filtered ("\", ", stream);
in_quotes = 0;
}
fputs_filtered ("'", stream);
printchar (string[i], stream, '\'');
fprintf_filtered (stream, "' <repeats %u times>", reps);
i = rep1 - 1;
things_printed += REPEAT_COUNT_THRESHOLD;
need_comma = 1;
}
else
{
if (!in_quotes)
{
fputs_filtered ("\"", stream);
in_quotes = 1;
}
printchar (string[i], stream, '"');
++things_printed;
}
}
/* Terminate the quotes if necessary. */
if (in_quotes)
fputs_filtered ("\"", stream);
if (force_ellipses || i < length)
fputs_filtered ("...", stream);
}
/* Print the value VAL in C-ish syntax on stream STREAM.
FORMAT is a format-letter, or 0 for print in natural format of data type.
If the object printed is a string pointer, returns
the number of string bytes printed. */
int
value_print (val, stream, format, pretty)
value val;
FILE *stream;
char format;
enum val_prettyprint pretty;
{
register unsigned int i, n, typelen;
/* A "repeated" value really contains several values in a row.
They are made by the @ operator.
Print such values as if they were arrays. */
if (VALUE_REPEATED (val))
{
n = VALUE_REPETITIONS (val);
typelen = TYPE_LENGTH (VALUE_TYPE (val));
fprintf_filtered (stream, "{");
/* Print arrays of characters using string syntax. */
if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
&& format == 0)
print_string (stream, VALUE_CONTENTS (val), n, 0);
else
{
unsigned int things_printed = 0;
for (i = 0; i < n && things_printed < print_max; i++)
{
/* Position of the array element we are examining to see
whether it is repeated. */
unsigned int rep1;
/* Number of repititions we have detected so far. */
unsigned int reps;
if (i != 0)
fprintf_filtered (stream, ", ");
rep1 = i + 1;
reps = 1;
while (rep1 < n
&& !bcmp (VALUE_CONTENTS (val) + typelen * i,
VALUE_CONTENTS (val) + typelen * rep1, typelen))
{
++reps;
++rep1;
}
if (reps > REPEAT_COUNT_THRESHOLD)
{
val_print (VALUE_TYPE (val),
VALUE_CONTENTS (val) + typelen * i,
VALUE_ADDRESS (val) + typelen * i,
stream, format, 1, 0, pretty);
fprintf (stream, " <repeats %u times>", reps);
i = rep1 - 1;
things_printed += REPEAT_COUNT_THRESHOLD;
}
else
{
val_print (VALUE_TYPE (val),
VALUE_CONTENTS (val) + typelen * i,
VALUE_ADDRESS (val) + typelen * i,
stream, format, 1, 0, pretty);
things_printed++;
}
}
if (i < n)
fprintf_filtered (stream, "...");
}
fprintf_filtered (stream, "}");
return n * typelen;
}
else
{
/* If it is a pointer, indicate what it points to.
Print type also if it is a reference.
C++: if it is a member pointer, we will take care
of that when we print it. */
if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR
|| TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
{
fprintf_filtered (stream, "(");
type_print (VALUE_TYPE (val), "", stream, -1);
fprintf_filtered (stream, ") ");
/* If this is a function pointer, try to print what
function it is pointing to by name. */
if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val)))
== TYPE_CODE_FUNC)
{
print_address (((int *) VALUE_CONTENTS (val))[0], stream);
/* Return value is irrelevant except for string pointers. */
return 0;
}
}
return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
}
}
/* Return truth value for assertion that TYPE is of the type
"pointer to virtual function". */
static int
is_vtbl_ptr_type(type)
struct type *type;
{
return (!strcmp(TYPE_NAME(type), "$vtbl_ptr_type"));
}
/* Return truth value for the assertion that TYPE is of the type
"pointer to virtual function table". */
static int
is_vtbl_member(type)
struct type *type;
{
if (TYPE_CODE (type) == TYPE_CODE_PTR
&& TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
&& TYPE_CODE (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type))) == TYPE_CODE_STRUCT)
/* Virtual functions tables are full of pointers to virtual functions. */
return is_vtbl_ptr_type (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)));
return 0;
}
static int prettyprint; /* Controls prettyprinting of structures. */
int unionprint; /* Controls printing of nested unions. */
int vtblprint; /* Controls printing of vtbl's */
/* Print data of type TYPE located at VALADDR (within GDB),
which came from the inferior at address ADDRESS,
onto stdio stream STREAM according to FORMAT
(a letter or 0 for natural format).
If the data are a string pointer, returns the number of
sting characters printed.
if DEREF_REF is nonzero, then dereference references,
otherwise just print them like pointers.
The PRETTY parameter controls prettyprinting. */
int
val_print (type, valaddr, address, stream, format,
deref_ref, recurse, pretty)
struct type *type;
char *valaddr;
CORE_ADDR address;
FILE *stream;
char format;
int deref_ref;
int recurse;
enum val_prettyprint pretty;
{
register unsigned int i;
int len, n_baseclasses;
struct type *elttype;
int eltlen;
LONGEST val;
unsigned char c;
if (pretty == Val_pretty_default)